{include file="public/header" /}
<style>
    .layui-layer-input{
        width:200px !important;
        font-size: 13px !important;
        margin: 0 20px !important;
    }
    .layui-layer-prompt .layui-layer-btn .layui-layer-btn0 , .layui-layer-prompt .layui-layer-btn .layui-layer-btn1{
        font-size: 14px !important;
    }
    .layui-layer-btn a{
        height: 30px !important;
        margin-top: 20px !important;
        line-height: 30px !important;
    }
</style>
<body>
<div class="header">
    <i class="layui-icon layui-icon-left" ></i> 个人资料
</div>

<div class="personal-news flex-center">
    <label for="check">
        <p class="flex-center">
            <img src="{if $user.photo}{$user.photo}{else}cache('system')['default_photo']{/if}" alt=""  id="photo">
        </p>
        <p>点击更换头像</p>
    </label>
</div>

<ul class="set-list">
    <li>
        <a href="javascript:;">姓名
            <div lay-on="prompt">{$user.nickname??''}
                <i class="layui-icon layui-icon-right"></i>
                <!-- <span class="saveNickname" lay-on="prompt">修改</span> -->
            </div>
        </a>
    </li>
    <li>
        <a href="javascript:;">手机号
            <div lay-on="prompt_mobile">{$user.mobile??''}
                <!-- <span class="saveNickname">修改</span> -->
                <i class="layui-icon layui-icon-right"></i>
            </div>
        </a>
    </li>
    <li>
        <a href="">推荐人ID
            <div>{$user.parent_code ?? '-'}
<!--                <i class="layui-icon layui-icon-right"></i>-->
            </div>
        </a>
    </li>

</ul>
</body>
{include file="public/footer"/}
<script>
    layui.use(function(){
      var layer = layui.layer;
      var util = layui.util;
      util.on('lay-on', {
        'prompt': function(){
          layer.prompt({title: '请输入姓名'}, function(value, index, elem){
            console
            if(value == ''){
                layer.msg('请输入姓名');  
                return  elem.focus();
            }
            $.post('{:url("user/edit")}', {nickname: value}, function (data) {
                layer.closeAll();
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000}, function () {
                        location.reload();
                    })
                }
            });
          });
        },
        'prompt_mobile': function(){
          layer.prompt({title: '请输入手机号'}, function(value, index, elem){
            console
            if(value == ''){
                layer.msg('请输入手机号');  
                return  elem.focus();
            }else{
                if(!(/^1[3-9]\d{9}$/.test(value))){
                    layer.msg('手机号码有误，请重填');
                    return  elem.focus();
                }
            }
            $.post('{:url("user/edit")}', {mobile: value}, function (data) {
                layer.closeAll();
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000}, function () {
                        location.reload();
                    })
                }
            });
          });
        },
      });
    });
    </script>
</html>